package com.beep.erp.common.widget.refresh.container;

import android.content.Context;
import android.graphics.drawable.AnimationDrawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.beep.erp.AppContext;
import com.beep.erp.R;
import com.beep.erp.common.glide.GlideImageLoader;


/**
 * FileName: DefaultHeader
 * description:下拉刷新动画
 * Author: 丁博洋
 * Date: 2018/8/18
 */
public class DefaultHeader extends BaseHeader{

    private Context context;
    private int rotationSrc;
    private int arrowSrc;
    private int logoSrc;
    private boolean isShowText;

    private AnimationDrawable animationDrawable;

    private TextView headerTitle;
    private ImageView headerArrow;
    private ImageView headerLogo;
    private View frame;

    public DefaultHeader(Context context){
        this(context, 0, R.mipmap.arrow,0,false);
    }

    public DefaultHeader(Context context,boolean isShowText){
        this(context, 0, R.mipmap.arrow,0,isShowText);
    }

    public DefaultHeader(Context context,int logoSrc){
        this(context, 0, R.mipmap.arrow,logoSrc,false);
    }

    public DefaultHeader(Context context,int logoSrc,boolean isShowText){
        this(context, 0, R.mipmap.arrow,logoSrc,isShowText);
    }

    public DefaultHeader(Context context,int rotationSrc,int arrowSrc,int logoSrc,boolean isShowText){
        this.context = context;
        this.rotationSrc = rotationSrc;
        this.arrowSrc = arrowSrc;
        this.logoSrc = logoSrc;
        this.isShowText = isShowText;
    }

    @Override
    public View getView(LayoutInflater inflater,ViewGroup viewGroup) {
        View view = inflater.inflate(R.layout.refresh_default_header, viewGroup, true);
        headerTitle = (TextView) view.findViewById(R.id.default_header_text);
        headerArrow = (ImageView) view.findViewById(R.id.default_header_arrow);
        headerLogo = (ImageView) view.findViewById(R.id.default_header_logo);
        frame = view.findViewById(R.id.default_frame);
        if(!isShowText) headerTitle.setVisibility(View.GONE);
//        headerArrow.setImageResource(arrowSrc);
        return view;
    }

    @Override
    public int getDragSpringHeight(View rootView) {
        return frame.getMeasuredHeight();
    }

    @Override
    public int getDragLimitHeight(View rootView) {
        return frame.getMeasuredHeight();
    }

    @Override
    public void onPreDrag(View rootView) {
    }

    @Override
    public void onDropAnim(View rootView, int dy) {
    }

    @Override
    public void onLimitDes(View rootView, boolean upORdown) {
        headerTitle.setVisibility(View.GONE);
        if (!upORdown){
            headerTitle.setText(R.string.refresh_header);
        }
        else {
            headerTitle.setText(R.string.refresh_header_down);
        }
    }

    @Override
    public void onStartAnim() {
        headerTitle.setVisibility(View.GONE);
//        headerArrow.setImageResource(R.drawable.refresh_list_animation);
        GlideImageLoader.load(AppContext.context(),R.mipmap.def,headerArrow);
/*        animationDrawable = (AnimationDrawable) headerArrow.getDrawable();
        animationDrawable.start();*/
    }

    @Override
    public void onFinishAnim() {
        headerTitle.setVisibility(View.GONE);
        headerTitle.setText(R.string.refresh_header_down);
    }
}
